﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;

namespace SV
{
    class Server
    {

        public Server(string ip, int port)
        {
            {
                IPAddress address = IPAddress.Parse(ip);
                TcpListener serverSocket = new TcpListener(address, port);
                TcpClient clientSocket = default(TcpClient);
                int counter = 0;
                serverSocket.Start();
                Console.WriteLine(" >> " + "Server Started");
                
                counter = 0;
                while (true)
                {
                    counter += 1;
                    clientSocket = serverSocket.AcceptTcpClient();
                    Console.WriteLine(" >> " + "Client No:" + Convert.ToString(counter) + " started!");
                    Client client = new Client();
                    client.startClient(clientSocket, Convert.ToString(counter));
                }

                serverSocket.Stop();
                Console.WriteLine(" >> " + "exit");
                Console.ReadLine();
            }

        }
    }
}
